//
//  ZNewTextViewCell.m
//  WeClubs
//
//  Created by Zed Link on 17/4/2017.
//  Copyright © 2017 Zed. All rights reserved.
//

#import "ZNewTextViewCell.h"

@interface ZNewTextViewCell () <UITextViewDelegate> 

@property (weak, nonatomic) IBOutlet UILabel *placeHolderLabel;


@end

@implementation ZNewTextViewCell

- (void)zSetupCell
{
    [super zSetupCell];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.contentView setBackgroundColor:NAVBAR_BG_COLOR];
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if (![text isEqualToString:@""])
    {
        self.placeHolderLabel.hidden = YES;
    }
    
    if ([text isEqualToString:@""] && range.location == 0 && range.length == 1) {
        self.placeHolderLabel.hidden = NO;
    }
    if (self.textViewTextHandlerCallBack) {
        
        self.textViewTextHandlerCallBack(textView.text);
    }
    
    
    return YES;
}

#pragma mark - Public Method

- (void)setPlaceHolderText:(NSString *)text
{
    [self.placeHolderLabel setText:text];
}

- (NSString *)inputText
{
    return self.textView.text;
}

- (void)setInputText:(NSString *)inputText
{
    self.textView.text = inputText;

    if (inputText.length > 0) {
        self.placeHolderLabel.hidden = YES;
    } else {
        self.placeHolderLabel.hidden = NO;
    }
}

@end
